package tut.collection.code;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;

public class ListTest {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		System.out.println();
		List list = new ArrayList();
		list.add("one");
		list.add("two");
		list.add("three");
		list.add("four");
		list.add(0, "zero1");
		list.add(0, "zero2");
		printList2(list);

		// access list via index
		System.out.println(list.get(2));

		// remove element by index or object
		list.remove(0);
		printList(list);
		list.remove("two");
		printList(list);

		ArrayList arr = new ArrayList();
		HashMap m = new HashMap();
		HashSet s = (HashSet) m.keySet();

	}

	public static void printList2(List list) {
		// iterating list use iterator
		Iterator i = list.iterator();
		while(i.hasNext()) {
			Object o = i.next();
			System.out.println(o);
		}

		System.out.println("--------------");

		// iterating list use for-loop
		for(Object o1: list) {
			System.out.println(o1);
		}
	}

	public static void printList(List list) {
		System.out.println("======print list======");
		Iterator i = list.iterator();
		while(i.hasNext()) {
			Object o = i.next();
			System.out.println(o);
		}
	}
/*
	=>remove(object)

*/
}
